/**
 * Created by Ado on 15/9/15.
 */
//module game{
    class GuideStep {
        public id:number;//real step id
        public steps:Step[];//no less than 1 step
        public curStepId:number = -1;
        public maxStep:number = -1;
        public constructor(data:any=null){
            if( data != null)
                this.initFromData(data);
        }

        public nextStep():Step{
            this.curStepId++;
            if( this.curStepId < this.steps.length)
                return this.steps[this.curStepId];
            else
                return null;
        }

        public initFromData(data:any){
            this.id = data.id;
            var steps:any[] = data.steps;
            this.steps = [];
            var len = steps.length;
            for(var idx = 0; idx < len; idx ++){
                this.steps.push(new Step(steps[idx]));
            }
            if( this.steps.length > 1){
                this.steps.sort(function(item0, item1):number{
                    if( item0.step > item1.step)
                    {
                        return 1;
                    }else{
                        return -1;
                    }
                })
            }

            this.maxStep = this.steps[idx-1].step;
            //this.curStepId = 0;
        }

        public destroy(){
            var step:Step;
            while( this.steps.length){
                step = this.steps.pop();
                step.destroy();
                step = null;
            }
            this.steps = null;
        }
    }
//}